package com.xst.business.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.mapping.Array;

import com.xst.business.OrderDao;
import com.xst.model.Customer;
import com.xst.model.Order;
import com.xst.model.Product;
import com.xst.util.BaseHibernateDAO;

public class OrderDaoImpl extends BaseHibernateDAO implements OrderDao {
	// private Session session;
	private List<Order> list = null;
	private List list2 = null;

	@Override
	public List<Order> getall() {
		try {
			// session = super.getSession();
			String hql = "from Order";
			list = super.getSession().createQuery(hql).list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		// finally{
		// session.close();
		// }
		return list;
	}

	// private Integer id;
	// private Customer customer;
	// private Date startDate;
	// private Date endDate;
	// private String status;
	// private String isSign;
	// private String takeName;
	// private String remark;

	@Override
	public List<HashMap<String, String>> getallinfo() {
		try {
			// session = super.getSession();
			String hql = "from Order";
			list = super.getSession().createQuery(hql).list();
			list2 = new ArrayList<HashMap<String, String>>();
			for (Order order : list) {
				HashMap<String, String> map = new HashMap<String, String>();
				map.put("id", order.getId().toString());
				map.put("customer", order.getCustomer().getName());
				map.put("startDate", order.getStartDate().toString());
				//------------
				if(null == order.getEndDate()){
					map.put("endDate", "");
				}else {
					map.put("endDate", order.getEndDate().toString());
				}
				//
				//
				//
				map.put("status", order.getStatus());
				map.put("isSign", order.getIsSign());
				map.put("takeName", order.getTakeName());
				map.put("remark", order.getRemark());
				list2.add(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		// finally{
		// session.close();
		// }

		return list2;
	}

}
